<template>
  <div id="app">
    <van-nav-bar
      v-if="showNavigationBar"
      :title="title"
      left-arrow
      left-text="返回"
      fixed
      placeholder
      :border="false"
      @click-left="onClickLeft"
      z-index="9999999"
    />
    <template v-if="enablePullDownRefresh">
      <!-- 下拉刷新动画 -->
      <page-refresh
        ref="refresh"
        :color="refreshOptions.color"
        :offset="refreshOptions.offset" />
      <router-view
        @touchstart.native="_touchstart"
        @touchmove.native="_touchmove"
        @touchend.native="_touchend"
        @touchcancel.native="_touchend"
      />
    </template>
    <template v-else>
      <router-view />
    </template>
  </div>
</template>

<script>
import { NavBar } from 'vant';
import { closeWebView } from './api/native';
import PageRefresh from './components/PageRefresh'
import PullToRefresh from './utils/pull_to_refresh'

export default {
  components: {
    [NavBar.name]: NavBar,
    PageRefresh
  },

  mixins: [PullToRefresh],

  data() {
    const refreshOptions = {
      support: true,
      color: '#2BD009',
      style: 'circle',
      height: 70,
      range: 150,
      offset: 0
    }

    return {
      title: document.title,  // 动态设置标题
      refreshOptions,
      showNavigationBar: false,
      enablePullDownRefresh: false,
    }
  },

  methods: {
    onClickLeft() {
      if(history.length > 1) {
        history.back();
      } else {
        closeWebView();
      }
    }
  }
}
</script>

<style lang="less">
@import '~normalize.css';
@weuiFontEN: -apple-system-font, "Helvetica Neue";
@weuiFontCN: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei";
@weuiFontSans: sans-serif;
@weuiFontDefault: @weuiFontEN, @weuiFontSans, @weuiFontCN;

body {
  font-size: 16px;
  background-color: #f5f5f6;
  -webkit-font-smoothing: antialiased;
  font-family: @weuiFontDefault;
}

* {
  box-sizing: border-box;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
ul {
  margin: 0;
}

ul {
  padding: 0;
}

table {
  border-spacing: 0;

  th {
    color: #5e6678;
    font-size: 14px;
    padding: 5px 15px;
  }

  td {
    border-bottom: 1px solid #efefef;
    padding: 10px 15px;
    color: #414141;
    font-size: 16px;

    h5 {
      margin: 0;
      line-height: 16px;
      font-size: 16px;
    }

    span {
      color: #5e6678;
      font-size: 12px;
      line-height: 6px;
    }
  }

  td,
  th {
    white-space: nowrap;
  }
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.pull-left {
  float: left;
}

.pull-right {
  float: right;
}

.clearfix {
  &::after {
    content: "";
    display: block;
    clear: both;
  }
}

.up {
  color: #eb333b !important;

  &.plus::before,
  .plus::before {
    content: "+";
    font-size: 15px;
  }
}

.down {
  color: #00b247 !important;
}

.gray {
  color: #414141 !important;
}

.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.tap-active {
  tap-highlight-color: rgba(0,0,0,0);
  user-select:none;
}
.tap-active:active {
  background-color: #ECECEC;
}

.icon {
  display: inline-block;
  background-size: contain;
  background-repeat: no-repeat;
  height: 14px;
  width: 14px;
}


.icon-follow {
  background-image: url("./assets/icon_info_cyrs_@x1@2x.png");
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

.icon-like {
  background-image: url("./assets/like@2x.png");
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

.icon-like-red {
  background-image: url("./assets/like_red@2x.png");
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

.icon-live-over {
  background-image: url("./assets/live_over.png");
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

.icon-warn {
  background-image: url('./assets/icon_warn.png');
  margin-right: 5px;
}

.icon-living {
  background-image: url("./assets/living@2x.png");
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

.icon-living-circle {
  background-image: url("./assets/icon_living_circle.png");
  height: 17px;
  width: 17px;
  margin-right: 5px;
}

.icon-live-over-circle {
  background-image: url("./assets/icon_live_over_circle.png");
  height: 17px;
  width: 17px;
  margin-right: 5px;
}

.icon-clock {
  background-image: url("./assets/icon_clock@2x.png");
  height: 14px;
  width: 14px;
  margin-right: 5px;
}

.icon-free {
  background-image: url("./assets/icon_free@2x.png");
  width: 45px;
  height: 20px;
}

.icon-read {
  background-image: url("./assets/icon_info_ydl_@x3@2x.png");
  width: 18px;
  height: 15px;
}

.icon-fire {
  background-image: url("./assets/icon_fire.png");
  width: 14px;
  height: 14px;
  margin-right: 5px;
}

.icon-live-corner {
  background-image: url("./assets/icon-live@2x.png");
  width: 18px;
  height: 18px;
}

.van-multi-ellipsis--l2, .van-multi-ellipsis--l3 {
  word-break: break-all;
}
.icon-pay0 {
  background-image: url("./assets/icon_pay@2x.png");
  width: 18px;
  height: 18px;
}
.icon-pay0-active {
  background-image: url("./assets/icon_pay_active@2x.png");
  width: 18px;
  height: 18px;
}
.icon-pay1 {
  background-image: url("./assets/icon_pay2.png");
  width: 18px;
  height: 18px;
}
.icon-pay1-active {
  background-image: url("./assets/icon_pay2_active@2x.png");
  width: 18px;
  height: 18px;
}

.order-ticket {
  position: relative;

  &::after {
    content: '';
    position: absolute;
    height: 5px;
    width:100%;
    left: 0;
    bottom: -5px;
    background-image: radial-gradient(15px circle at bottom center, transparent 5px, #fff 5px, #fff 5px);
    background-size: 11px 5px;
  }
}

#app {
  .van-nav-bar {
    background-color: #202020;

    .van-nav-bar__title {
      color: #fff;
    }

    .van-nav-bar__arrow {
      color: #999;
      font-size: 22px;
    }

    .van-nav-bar__text {
      color: #999;
      font-size: 16px;
    }
  }
}

</style>
